//
//  ViewController.m
//  MVCTest
//
//  Created by Noah on 2017/5/19.
//  Copyright © 2017年 Noah. All rights reserved.
//

#import "ViewController.h"
#import "TestView.h"
#import "TestModel.h"

@interface ViewController ()<TestViewDelegate>

@property(strong,nonatomic)TestModel *testmodel; // 负责处理数据
@property(strong,nonatomic)TestView *testView;   // 负责数据展示和交互

@property(strong,nonatomic)UITextView *textView; // 

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.testView = [[TestView alloc]initWithFrame:CGRectMake(0, 20, deviceScreenWidth, 100)];
    self.testView.backgroundColor = [UIColor whiteColor];
    self.testView.delegate = self;
    [self.view addSubview:self.testView];
    
    self.testmodel = [[TestModel alloc]init];
    
    self.textView = [[UITextView alloc]init];
    [self.textView setFrame:CGRectMake(0, 120, deviceScreenWidth, 300)];
    self.textView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:self.textView];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationOfSaveSuccess:) name:KSAVESUCCESS object:nil];
    
}

-(void)notificationOfSaveSuccess:(NSNotification*)noti{
    id object = [noti object];
    if ([object isKindOfClass:[NSDictionary class]]) {
        NSLog(@"%@",object);
        [self.testView showMessage:object];
        
    }
}

#pragma mark ------TestViewDelegate-------
-(void)editMessageWithTestView:(TestView *)testView{
    [self.testmodel editMessage:self.textView.text];
}
-(void)saveMessageWithTestView:(TestView *)testView{
    [self.testmodel saveMessage];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
